﻿using Estsh.Core.Model.EnumUtil;
using Estsh.Core.Models;
using Estsh.Core.Quartz.BaseService;
using Estsh.Core.Util;
using Estsh.Core.Wms.IRepositories;

namespace Estsh.Core.Wms.Jobs
{
    /// <summary>
    /// 从SAP传递物料号与客户物料号对照信息到WMS
    /// </summary>
    public class InterfaceCustomerItemMasterJob : IJobService
    {
        private readonly IInterfaceMasterRepository repository;


        public InterfaceCustomerItemMasterJob(IInterfaceMasterRepository _repository)
        {
            this.repository = _repository;

        }

        public string ExecuteService(string parameter)
        {
            try
            {
                List<SapPtcpt> sapPtcpts = repository.GetCustomerItemMasterInfo();
                if (sapPtcpts.Count <= 0)
                {
                    return "没有待处理的物料号与客户物料号对照信息！";
                }

                bool bl = repository.InsertCustomerItemMasterInfo(sapPtcpts);
                if (bl==true)
                {
                    return "物料号与客户物料号对照信息同步成功！";
                }
                else
                {
                    return "物料号与客户物料号对照信息同步失败！";
                }
            }
            catch (Exception ex)
            {
                LogHelper.Error("物料号与客户物料号对照信息同步错误！" + ex);
                return "物料号与客户物料号对照信息同步错误！" + ex.Message;
            }
        }

    }
}
